﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('OutpVisitRecord:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-input v-model="queryParam.outpMedicalNo" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-input v-model="queryParam.registerNo" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.patientName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.patientSex" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.patientAge" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.patientBirthdayDate" @change="onChangepatientBirthday"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.balanceType" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.visitDateDate" @change="onChangevisitDate"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.operDateDate" @change="onChangeoperDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.operCode" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.operName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.primaryDiagnose" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.primaryDiagnoseName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.doctorCode" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.doctorName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.deptCode" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.deptName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.state" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.visitNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.societyInsuranceNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.idNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.icNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.citizenship" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.nation" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.workUnit" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.mailingAddress" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.occupation" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.maritalStatus" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.inputCode" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.remark" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.nativePlace" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.admNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.back" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.back1" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.back2" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.illnessDateDate" @change="onChangeillnessDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.patHeight" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.phoneNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.emergency" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.mensesDate" @change="onChangemenses"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.secondDiagnoseName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.motherName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.motherTel" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.fatherName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.fatherTel" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.otherName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.otherTel" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.back4" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.danganNo" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.back3" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="创建时间">
                  <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-model="queryParam.creatceDateDate" @change="onChangecreatceDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者Id">
                  <a-input v-model="queryParam.createUserId" allow-clear placeholder="请输入创建者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者名称">
                  <a-input v-model="queryParam.createUserName" allow-clear placeholder="请输入创建者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="更新时间">
                  <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-model="queryParam.modifyDateDate" @change="onChangemodifyDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者Id">
                  <a-input v-model="queryParam.modifyUserId" allow-clear placeholder="请输入修改者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者名称">
                  <a-input v-model="queryParam.modifyUserName" allow-clear placeholder="请输入修改者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="删除时间">
                  <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-model="queryParam.deleteDateDate" @change="onChangedeleteDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者ID">
                  <a-input v-model="queryParam.deleteUserId" allow-clear placeholder="请输入删除者ID"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者姓名">
                  <a-input v-model="queryParam.deleteUserName" allow-clear placeholder="请输入删除者姓名"/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('OutpVisitRecord:add')" >
          <a-button type="primary" v-if="hasPerm('OutpVisitRecord:add')" icon="plus" @click="$refs.addForm.add()">新增就诊记录</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('OutpVisitRecord:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('OutpVisitRecord:edit') & hasPerm('OutpVisitRecord:delete')"/>
          <a-popconfirm v-if="hasPerm('OutpVisitRecord:delete')" placement="topRight" title="确认删除？" @confirm="() => OutpVisitRecordDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { OutpVisitRecordPage, OutpVisitRecordDelete } from '@/api/modular/main/OutpVisitRecordManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: '',
            align: 'center',
            dataIndex: 'outpMedicalNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'registerNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'patientName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'patientSex'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'patientAge'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'patientBirthday'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'balanceType'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'visitDate'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'operDate'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'operCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'operName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'primaryDiagnose'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'primaryDiagnoseName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'doctorCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'doctorName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'deptCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'deptName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'state'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'visitNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'societyInsuranceNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'idNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'icNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'citizenship'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'nation'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'workUnit'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'mailingAddress'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'occupation'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'maritalStatus'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'inputCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'nativePlace'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'admNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'back'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'back1'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'back2'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'illnessDate'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'patHeight'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'phoneNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'emergency'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'menses'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'secondDiagnoseName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'motherName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'motherTel'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'fatherName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'fatherTel'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'otherName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'otherTel'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'back4'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'danganNo'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'back3'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'creatceDate'
          },
          {
            title: '创建者Id',
            align: 'center',
            dataIndex: 'createUserId'
          },
          {
            title: '创建者名称',
            align: 'center',
            dataIndex: 'createUserName'
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'modifyDate'
          },
          {
            title: '修改者Id',
            align: 'center',
            dataIndex: 'modifyUserId'
          },
          {
            title: '修改者名称',
            align: 'center',
            dataIndex: 'modifyUserName'
          },
          {
            title: '删除时间',
            align: 'center',
            dataIndex: 'deleteDate'
          },
          {
            title: '删除者ID',
            align: 'center',
            dataIndex: 'deleteUserId'
          },
          {
            title: '删除者姓名',
            align: 'center',
            dataIndex: 'deleteUserName'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return OutpVisitRecordPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('OutpVisitRecord:edit') || this.hasPerm('OutpVisitRecord:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParampatientBirthday = this.queryParam.patientBirthdayDate
        if (queryParampatientBirthday != null) {
            this.queryParam.patientBirthday = moment(queryParampatientBirthday).format('YYYY-MM-DD')
            if (queryParampatientBirthday.length < 1) {
                delete this.queryParam.patientBirthday
            }
        }
        const queryParamvisitDate = this.queryParam.visitDateDate
        if (queryParamvisitDate != null) {
            this.queryParam.visitDate = moment(queryParamvisitDate).format('YYYY-MM-DD')
            if (queryParamvisitDate.length < 1) {
                delete this.queryParam.visitDate
            }
        }
        const queryParamoperDate = this.queryParam.operDateDate
        if (queryParamoperDate != null) {
            this.queryParam.operDate = moment(queryParamoperDate).format('YYYY-MM-DD')
            if (queryParamoperDate.length < 1) {
                delete this.queryParam.operDate
            }
        }
        const queryParamillnessDate = this.queryParam.illnessDateDate
        if (queryParamillnessDate != null) {
            this.queryParam.illnessDate = moment(queryParamillnessDate).format('YYYY-MM-DD')
            if (queryParamillnessDate.length < 1) {
                delete this.queryParam.illnessDate
            }
        }
        const queryParammenses = this.queryParam.mensesDate
        if (queryParammenses != null) {
            this.queryParam.menses = moment(queryParammenses).format('YYYY-MM-DD')
            if (queryParammenses.length < 1) {
                delete this.queryParam.menses
            }
        }
        const queryParamcreatceDate = this.queryParam.creatceDateDate
        if (queryParamcreatceDate != null) {
            this.queryParam.creatceDate = moment(queryParamcreatceDate).format('YYYY-MM-DD')
            if (queryParamcreatceDate.length < 1) {
                delete this.queryParam.creatceDate
            }
        }
        const queryParammodifyDate = this.queryParam.modifyDateDate
        if (queryParammodifyDate != null) {
            this.queryParam.modifyDate = moment(queryParammodifyDate).format('YYYY-MM-DD')
            if (queryParammodifyDate.length < 1) {
                delete this.queryParam.modifyDate
            }
        }
        const queryParamdeleteDate = this.queryParam.deleteDateDate
        if (queryParamdeleteDate != null) {
            this.queryParam.deleteDate = moment(queryParamdeleteDate).format('YYYY-MM-DD')
            if (queryParamdeleteDate.length < 1) {
                delete this.queryParam.deleteDate
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      OutpVisitRecordDelete (record) {
        OutpVisitRecordDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangepatientBirthday(date, dateString) {
        this.patientBirthdayDateString = dateString
      },
      onChangevisitDate(date, dateString) {
        this.visitDateDateString = dateString
      },
      onChangeoperDate(date, dateString) {
        this.operDateDateString = dateString
      },
      onChangeillnessDate(date, dateString) {
        this.illnessDateDateString = dateString
      },
      onChangemenses(date, dateString) {
        this.mensesDateString = dateString
      },
      onChangecreatceDate(date, dateString) {
        this.creatceDateDateString = dateString
      },
      onChangemodifyDate(date, dateString) {
        this.modifyDateDateString = dateString
      },
      onChangedeleteDate(date, dateString) {
        this.deleteDateDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
